package com.ayz.gateway.core.session.defaults;

import com.ayz.gateway.core.context.config.Configuration;
import com.ayz.gateway.core.datasource.DatasourceFactory;
import com.ayz.gateway.core.session.GatewaySession;
import com.ayz.gateway.core.session.GatewaySessionFactory;
import com.ayz.gateway.core.session.processor.RpcPostProcessorRegistry;
import lombok.Data;

/**
 * @ClassName DefaultGatewaySessionFactory
 * @Description TODO: 默认的网关上下文会话工厂
 * @Author 快乐的星球
 * @Date 2023/5/8 11:50
 * @Version 1.0
 **/
@Data
public class DefaultGatewaySessionFactory implements GatewaySessionFactory {
    /**
     * 立足于网关上下文的配置项
     */
    private Configuration configuration;
    /**
     * 连接数据源工厂类
     */
    private DatasourceFactory datasourceFactory;
    /**
     * 立足于网关上下文级别的处理器注册器
     */
    private RpcPostProcessorRegistry postProcessorRegistry;

    public DefaultGatewaySessionFactory(Configuration configuration,DatasourceFactory datasourceFactory
    ,RpcPostProcessorRegistry postProcessorRegistry){
        this.configuration=configuration;
        this.datasourceFactory=datasourceFactory;
        this.postProcessorRegistry=postProcessorRegistry;
    }
    @Override
    public GatewaySession openSession() {
        return new DefaultGatewaySession(configuration,datasourceFactory,postProcessorRegistry);
    }
}
